package com.bwie.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.mapper.ImagesMapper;
import com.bwie.mapper.IntroduceMapper;
import com.bwie.pojo.Images;
import com.bwie.pojo.Introduce;
import com.bwie.pojo.Park;
import com.bwie.service.ParkService;
import com.bwie.mapper.ParkMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author xueji
 * @description 针对表【park】的数据库操作Service实现
 * @createDate 2024-09-04 10:00:20
 */
@Service
public class ParkServiceImpl extends ServiceImpl<ParkMapper, Park>
        implements ParkService {

    @Autowired
    private ParkMapper parkMapper;

    @Autowired
    private IntroduceMapper introduceMapper;

    @Autowired
    private ImagesMapper imagesMapper;


    @Override
    @Transactional
    public void parkAdd(Park park) {
        //添加球场介绍富文本
        Introduce introduce = new Introduce();
        introduce.setIntroduceName(park.getIntroduceName());
        introduceMapper.insert(introduce);

        //然后添加球场数据
        park.setIntroduceId(introduce.getId());
        parkMapper.insert(park);

        String[] imagesList = park.getImagesList();
        for (String s : imagesList) {
            String[] split = s.split(",");
            Images images = new Images();
            images.setCarId(park.getId());
            for (String s1 : split) {
                images.setUrl(s1);
            }
            imagesMapper.insert(images);
        }
    }

    @Override
    public List<Park> parktuList() {
        return parkMapper.parktuList();
    }
}




